"""
蒙特卡洛（统计模拟法）算法求取π值
"""
import random
sample_num = int(input("请输入样本数："))  # 获取样本数
result = 0  # 定义落点
pi = 0  # 定义π初值
for i in range(sample_num):  # 循环获得落点
    a = random.uniform(0, 1)
    b = random.uniform(0, 1)
    if a*a + b*b <= 1:       # 确定落点范围
        result += 1
pi = (result / sample_num) * 4  # 求取π
print(f"样本数：{sample_num}，π近似等于：{pi}")